/*
 * @Description  : vite 公用配置
 * @Version      : 1.0
 * @Author       :kangshifu
 * @Date         : 2022-05-30 17:27:09
 * @LastEditors  : kangshifu
 * @LastEditTime : 2022-06-08 11:23:30
 */
import path from "path";
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
// import styleImport from 'vite-plugin-style-import';


export default defineConfig({
    define: {
        'process.env': {}
    },
    build:{
        outDir: 'dist',
    },
    base: process.env.VITE_PUBLIC_PATH,
    // chainWebpack: config => {
    //     config.module
    //         .rule('vue')
    //         .use('vue-loader')
    // },
    plugins: [
        vue(),
        // 兼容es6高级语法低版本手机 浏览器
        legacy({
            polyfills: ['es.promise.finally', 'es/map', 'es/set'],
            modernPolyfills: ['es.promise.finally'],
            targets: ['defaults', 'not IE 11']
        }),
        // 按需引入
        // styleImport({
        //     libs: [{
        //         libraryName: 'vant',
        //         esModule: true,
        //         resolveStyle: (name) => `vant/es/${name}/style`,
        //     }, ],
        // }),
    ],
    resolve: {
        alias: {
            "@": path.resolve(__dirname, "src")
        }
    },
    server: {
        host: '0.0.0.0',
        proxy: {
            '/api': {
                target:process.env.VITE_BASE_URL, //实际请求地址
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, '')
            },
        }
    },
})
